package com.bjpowernode.service.impl;

import com.bjpowernode.mapper.TActivityMapper;
import com.bjpowernode.mapper.TClueMapper;
import com.bjpowernode.mapper.TCustomerMapper;
import com.bjpowernode.mapper.TTranMapper;
import com.bjpowernode.result.NameValueData;
import com.bjpowernode.result.SummaryData;
import com.bjpowernode.service.StatisticService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Service
@RequiredArgsConstructor
public class StatisticServiceImpl implements StatisticService {


    private final TActivityMapper tActivityMapper;

    private final TClueMapper tClueMapper;

    private final TCustomerMapper tCustomerMapper;

    private final TTranMapper tTranMapper;

    @Override
    public SummaryData getSummaryData() {
        //进行中的市场活动
        Integer goingActivityCount = tActivityMapper.selectGoingActivityCount();

        //市场活动总数
        Integer totalActivityCount = tActivityMapper.selectTotalActivityCount();

        //线索总数
        Integer totalClueCount = tClueMapper.selectTotalClueCount();

        //客户总数
        Integer totalCustomerCount = tCustomerMapper.selectTotalCustomerCount();

        //成功交易额
        BigDecimal successTranAmount = tTranMapper.selectSuccessTranMoney();

        //总交易额
        BigDecimal totalTranAmount = tTranMapper.selectTotalTranMoney();


        SummaryData summaryData = SummaryData.builder()
                .goingActivityCount(goingActivityCount)
                .totalActivityCount(totalActivityCount)
                .totalClueCount(totalClueCount)
                .totalCustomerCount(totalCustomerCount)
                .successTranAmount(successTranAmount)
                .totalTranAmount(totalTranAmount)
                .build();
        return summaryData;
    }

    /**
     * 销售漏斗
     * @return
     */
    @Override
    public List<NameValueData> getSaleFunnel() {
        List<NameValueData> nameValueDataList = new ArrayList<>();

        //线索总数
        Integer totalClueCount = tClueMapper.selectTotalClueCount();
        NameValueData clueData = NameValueData.builder().name("线索").value(totalClueCount).build();
        nameValueDataList.add(clueData);

        //客户总数
        Integer totalCustomerCount = tCustomerMapper.selectTotalCustomerCount();
        NameValueData customerData = NameValueData.builder().name("客户").value(totalCustomerCount).build();
        nameValueDataList.add(customerData);

        //交易总数
        Integer totalTranCount = tTranMapper.selectTotalTranCount();
        NameValueData tranData = NameValueData.builder().name("交易").value(totalTranCount).build();
        nameValueDataList.add(tranData);

        //成交总数
        BigDecimal successTranAmount = tTranMapper.selectSuccessTranCount();
        NameValueData successTranData = NameValueData.builder().name("成交").value(successTranAmount).build();
        nameValueDataList.add(successTranData);

        return nameValueDataList;
    }

    @Override
    public List<NameValueData> getCluePie() {
        return tClueMapper.selectClueSourceCont();
    }
}
